package com.cruise.game.controller.user;

import com.cruise.game.common.api.ApiResult;
import com.cruise.game.common.constants.CommonConstants;
import com.cruise.game.controller.BaseController;
import com.cruise.game.model.vo.common.PageResult;
import com.cruise.game.model.vo.user.TransactionVO;
import com.cruise.game.model.vo.user.WithdrawalVO;
import com.cruise.game.service.user.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 用户交易控制器
 * 
 * @author cruise
 * @date 2025-02-28
 */
@Slf4j
@Api(tags = "用户交易相关接口")
@RestController
@RequestMapping("/api/user")
public class UserTransactionController extends BaseController {

    @Resource
    private UserService userService;

    /**
     * 获取交易记录
     */
    @ApiOperation("获取交易记录")
    @GetMapping("/transactions")
    public ApiResult<PageResult<TransactionVO>> getTransactions(
            @ApiParam(value = "交易类型", required = false)
            @RequestParam(value = "type", required = false) String type,
            
            @ApiParam(value = "页码", required = false, defaultValue = "1")
            @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
            
            @ApiParam(value = "每页条数", required = false, defaultValue = "10")
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        
        // 限制最大页面大小
        if (pageSize > CommonConstants.MAX_PAGE_SIZE) {
            pageSize = CommonConstants.MAX_PAGE_SIZE;
        }
        
        return ApiResult.success(userService.getTransactions(getCurrentUserId(), type, page, pageSize));
    }

    /**
     * 获取提现申请列表
     */
    @ApiOperation("获取提现申请列表")
    @GetMapping("/withdrawals")
    public ApiResult<PageResult<WithdrawalVO>> getWithdrawals(
            @ApiParam(value = "申请状态", required = false)
            @RequestParam(value = "status", required = false) String status,
            
            @ApiParam(value = "页码", required = false, defaultValue = "1")
            @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
            
            @ApiParam(value = "每页条数", required = false, defaultValue = "10")
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        
        // 限制最大页面大小
        if (pageSize > CommonConstants.MAX_PAGE_SIZE) {
            pageSize = CommonConstants.MAX_PAGE_SIZE;
        }
        
        return ApiResult.success(userService.getWithdrawals(getCurrentUserId(), status, page, pageSize));
    }
}
